<!--
 * @Author: 鸿羽飞舟 2653235481@qq.com
 * @Date: 2022-10-12 14:31:02
 * @LastEditors: 鸿羽飞舟 2653235481@qq.com
 * @LastEditTime: 2022-10-18 09:06:27
 * @FilePath: \briup-ui\src\pages\admin\log\List.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <!-- 表单 -->
    <template>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="序号" width="150" />
        <el-table-column prop="realname" label="访问人姓名">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.realname }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="method" label="访问方式" />
        <el-table-column prop="content" label="访问路径" />
        <el-table-column prop="logTime" label="访问时间">
          <template slot-scope="scope">
            <span>{{ scope.row.logTime | fmtTime }}</span>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <!-- 表单 -->

    <!-- 分页 -->
    <div class="log_page">
      <el-pagination
        :current-page="params.page"
        :page-sizes="[5, 10, 20, 50, 100]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
    <!-- 分页 -->

  </div>
</template>

<script>
import { pagelogQuery } from '@/api/log'

export default {
  data() {
    return {
      // 表单对象和分页数据
      params: {
        page: 1,
        pageSize: 10
      },
      // 表格数据
      tableData: [],
      // 总条数
      total: 0,
      // 控制白屏加载动画
      loading: false
    }
  },
  computed: {},
  created() {
    this.getLogById()
  },
  mounted() {},
  methods: {
    // 表格/表单
    // 获取数据
    // 根据分页获取对应信息
    async getLogById() {
      // 数据获取之前加载动画
      this.loading = true
      for (const key in this.params) {
        if (!this.params[key]) {
          delete this.params[key]
        }
      }
      const res = await pagelogQuery(this.params)
      // console.log(res, "获取响应");
      this.tableData = res.data.list
      this.total = res.data.total
      // 关闭加载动画
      this.loading = false
    },

    // 分页
    // 页码条数发生改变的方法
    handleSizeChange(pageSize) {
      this.params.pageSize = pageSize
      this.params.page = 1
      this.getLogById()
    },
    // 当前页码发生改变触发的方法
    handleCurrentChange(page) {
      this.params.page = page
      this.getLogById()
    }
  }
}
</script>
<style scoped>
.log_page {
  margin-top: 50px;
}
</style>
